import 'package:bloctest/model/hotkey_model.dart';
import 'package:bloctest/utils/base/BasePresenter.dart';
import 'package:bloctest/utils/http/dio_instance.dart';

import 'hot_page.dart';
import 'package:dio/dio.dart';

class HotPagePresenter extends BasePresenter<HotPageState> {
  HotPagePresenter(super.state);

  Future getUrl() async {}

  @override
  Future<void> loadData(Map<String, dynamic> loadDataParams) async {
    await getHotList();
    await getCustomUrlList();
    state?.notify();

    // TODO: implement loadData
    return super.loadData(loadDataParams);
  }

  Future<void> getHotList() async {
    Response response = await DioInstance.instance().doGet("hotkey/json", null);
    HotKetModel model = HotKetModel.fromJson(response.data);
    if (model.hotList != null) {
      state?.topList = model.hotList!;
    } else {
      state?.topList = [];
    }
  }

  Future<void> getCustomUrlList() async {
    Response response = await DioInstance.instance().doGet("friend/json", null);
    HotKetModel model = HotKetModel.fromJson(response.data);
    if (model.hotList != null) {
      state?.urlList = model.hotList!;
    } else {
      state?.urlList = [];
    }
    state?.notify();
  }
}
